<?php
require('config.php');

        $user_id=$_REQUEST['user_id'];
		//$user_id=9;
		/*
		$sql="select * from `".$oto."_orders` where `userId`='{$user_id}' and orderFlag='1' and orderStatus='-2' and orderType!='4'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$daifu[]=$row;//将取得的所有数据赋值给person_info数组
		}
		*/
		$sql="select * from `".$oto."_orders`,`".$oto."_order_goods`,`".$oto."_shops` where ".$oto."_orders.userId='".$user_id."' and `orderFlag`='1' and ".$oto."_orders.orderId=".$oto."_order_goods.orderId and ".$oto."_shops.shopId=".$oto."_orders.shopId and ".$oto."_orders.orderStatus='-2' order by ".$oto."_orders.createTime DESC";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$order[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(isset($order))
		{
			$pan_tiao=0;
			$t=0;
			for($i=0;$i<count($order);$i++)
			{
				if($order[$i]['orderId']!=$pan_tiao)
				{
					$daifu[$t]['orderId']=$order[$i]['orderId'];
					$daifu[$t]['shopName']=$order[$i]['shopName'];
					$daifu[$t]['shopImg']=$order[$i]['shopImg'];
					$daifu[$t]['shopId']=$order[$i]['shopId'];
					$daifu[$t]['needPay']=$order[$i]['needPay'];
					$daifu[$t]['orderStatus']=$order[$i]['orderStatus'];
					$daifu[$t]['deliverMoney']=$order[$i]['deliverMoney'];
					$t2=0;
					for($j=0;$j<count($order);$j++)
					{
						if($order[$i]['orderId']==$order[$j]['orderId'])
						{
							$daifu[$t]['list'][$t2]=$order[$j];
							$t2++;
						}
					}
					if($t2==0) $daifu[$t]['list']=[];
					$t++;
					$pan_tiao=$order[$i]['orderId'];
				}
			}
		}
		$sql="select * from `".$oto."_orders` where `userId`='{$user_id}' and orderFlag='1' and orderType!='4' and (orderStatus='1' or orderStatus='0' or orderStatus='2') ";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$daifa[]=$row;//将取得的所有数据赋值给person_info数组
		}
		$sql="select * from `".$oto."_orders` where `userId`='{$user_id}' and orderFlag='1' and orderStatus='3' and orderType!='4'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$daishou[]=$row;//将取得的所有数据赋值给person_info数组
		}
		//$sql="select * from `".$oto."_orders` where `userId`='{$user_id}' and orderFlag='1' and orderStatus='4'";
		$sql="select * from `".$oto."_orders`,`".$oto."_order_goods`,`".$oto."_shops` where ".$oto."_orders.userId='".$user_id."' and `orderFlag`='1' and ".$oto."_orders.orderId=".$oto."_order_goods.orderId and ".$oto."_shops.shopId=".$oto."_orders.shopId and ".$oto."_orders.orderStatus='4'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$daipingjia[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(isset($daipingjia))
		{
			for($i=0;$i<count($daipingjia);$i++)
			{
				$goods_id=$daipingjia[$i]['goodsId'];
				$order_id=$daipingjia[$i]['orderId'];
				$sql="select * from `".$oto."_goods_appraises` where orderId='{$order_id}' and goodsId='{$goods_id}' and userId='{$user_id}'";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$pingjia_info[$i]=$row;//将取得的所有数据赋值给person_info数组
				}
				if(!isset($pingjia_info[$i]))
				{
					$daipingjia2[]=$daipingjia[$i];
				}
			}
		}
		$sql="select * from `".$oto."_orders` as o,`".$oto."_order_goods` as g,`".$oto."_shops` as s where o.userId='".$user_id."' and `orderFlag`='1' and o.orderId=g.orderId and s.shopId=o.shopId and orderStatus in ('-6','-7','-3','-8') order by o.createTime DESC";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$tuikuan_info[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(!isset($daifu))
		{
			$data[0]['daifu']=0;
		}
		else
		{
			$data[0]['daifu']=count($daifu);
		}

		if(!isset($daifa))
		{
			$data[0]['daifa']=0;
		}
		else
		{
			$data[0]['daifa']=count($daifa);
		}

		if(!isset($daishou))
		{
			$data[0]['daishou']=0;
		}
		else
		{
			$data[0]['daishou']=count($daishou);
		}

		if(!isset($daipingjia2))
		{
			$data[0]['daipingjia']=0;
		}
		else
		{
			$data[0]['daipingjia']=count($daipingjia2);
		}
		if(!isset($tuikuan_info))
		{
			$data[0]['tuikuan']=0;
		}
		else
		{
			$data[0]['tuikuan']=count($tuikuan_info);
			$pan_tiao=0;$t=0;
			for($i=0;$i<count($tuikuan_info);$i++)
			{
				if($tuikuan_info[$i]['orderunique']!=$pan_tiao)
				{
					$t++;
					$pan_tiao=$tuikuan_info[$i]['orderunique'];
				}
			}
			$data[0]['tuikuan']=$t;
		}
		echo json_encode($data);
?>